package com.zxjbyte.yiyi.module.system.controller.oss;

import com.zxjbyte.yiyi.framework.common.domain.api.PageResult;
import com.zxjbyte.yiyi.framework.common.domain.api.R;
import com.zxjbyte.yiyi.module.system.domain.param.OssConfigAddParam;
import com.zxjbyte.yiyi.module.system.domain.param.OssConfigListParam;
import com.zxjbyte.yiyi.module.system.domain.param.OssConfigUpdateParam;
import com.zxjbyte.yiyi.module.system.domain.vo.OssConfigListVO;
import com.zxjbyte.yiyi.module.system.service.oss.OssConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @Author zhangxingjia
 * @Date 2023/5/11 16:14
 * @Version: 1.0
 */
@Slf4j
@Tag(name = "oss对象存储配置")
@RestController
@RequestMapping(value = "/system/ossconfig")
public class OssConfigController {

    @Resource
    private OssConfigService ossConfigService;

    @Operation(summary = "对象存储配置分页查询")
    @GetMapping("/list")
    public PageResult<OssConfigListVO> list(@ParameterObject OssConfigListParam param){
        return ossConfigService.list(param);
    }

    @Operation(summary = "新增对象存储配置")
    @PostMapping("/add")
    public R<?> add(@Valid @RequestBody OssConfigAddParam param){
        ossConfigService.add(param);
        return R.ok();
    }

    @Operation(summary = "编辑对象存储配置")
    @PutMapping("/update")
    public R<?> update(@Valid @RequestBody OssConfigUpdateParam param){
        ossConfigService.update(param);
        return R.ok();
    }

    @Operation(summary = "切换为主配置")
    @Parameter(name = "id", description = "唯一id" )
    @PutMapping("/changeMaster")
    public R<?> changeMaster(@RequestParam("id") Long id){
        ossConfigService.changeMaster(id);
        return R.ok();
    }

    @Operation(summary = "删除对象存储配置")
    @Parameter(name = "id", description = "唯一id" )
    @DeleteMapping("/delete")
    public R<?> delete(@RequestParam("id") Long id){
        ossConfigService.delete(id);
        return R.ok();
    }
}
